package myJs.admin

import myJs.Utils.g

import scala.scalajs.js
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}


/**
 * Created by yz on 2019/4/25
 */
@JSExportTopLevel("ChangePassword")
object ChangePassword {

  @JSExport("init")
  def init = {
    bootStrapValidator
  }

  def bootStrapValidator = {
    val url = g.jsRoutes.controllers.AdminController.userNameCheck().url.toString
    val dict = js.Dictionary(
      "feedbackIcons" -> js.Dictionary(
        "valid" -> "glyphicon glyphicon-ok",
        "invalid" -> "",
        "validating" -> "glyphicon glyphicon-refresh",
      ),
      "fields" -> js.Dictionary(
        "password" -> js.Dictionary(
          "validators" -> js.Dictionary(
            "notEmpty" -> js.Dictionary(
              "message" -> "密码不能为空！"
            ),
          )
        ),
        "newPassword" -> js.Dictionary(
          "validators" -> js.Dictionary(
            "notEmpty" -> js.Dictionary(
              "message" -> "新密码不能为空！"
            ),
            "identical" -> js.Dictionary(
              "field" -> "newPasswordAgain",
              "message" -> "两次密码不一样!"
            ),
            "regexp" -> js.Dictionary(
              "message" -> "新密码只能由数字和字母组成，必须同时包含大小写，且不小于6位！",
              "regexp" -> js.RegExp("^(?=[0-9a-zA-Z]*\\d)(?=[0-9a-zA-Z]*[A-Z])(?=[0-9a-zA-Z]*[a-z])[0-9a-zA-Z]{6,}$"),
            ),
          )
        ),
        "newPasswordAgain" -> js.Dictionary(
          "validators" -> js.Dictionary(
            "notEmpty" -> js.Dictionary(
              "message" -> "确认密码不能为空！"
            ),
            "identical" -> js.Dictionary(
              "field" -> "newPassword",
              "message" -> "两次密码不一样!"
            )
          )
        ),
      )
    )
    g.$("#form").bootstrapValidator(dict)
  }

}
